package com.cct.digitalarchapi.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cct.digitalarchapi.common.Response;
import com.cct.digitalarchapi.dao.ArchDeptHotpointMapper;
import com.cct.digitalarchapi.pojo.ArchDeptCategory;
import com.cct.digitalarchapi.pojo.ArchDeptHotpoint;
import com.cct.digitalarchapi.pojo.DigitalArchMain;
import com.cct.digitalarchapi.service.ArchDeptHotpointService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @FileName ArchCategoryServiceImpl
 * @Description 档案分类实现类
 * @Author Created by chenmingzhe
 * @Date 2023/11/19
 **/
@Slf4j
@Service
public class ArchDeptHotpointServiceImpl implements ArchDeptHotpointService {

    @Autowired
    private ArchDeptHotpointMapper archDeptHotpointMapper;



    @Override
    public Response addHotpoint(ArchDeptHotpoint archDeptHotpoint) {
        try{
            String num =archDeptHotpointMapper.qryHaveHotPoint(archDeptHotpoint.getArchDeptHotName());
            if("0".equals(num)) {
                archDeptHotpointMapper.addHotpoint(archDeptHotpoint);
                return Response.success("");
            }else{
                return Response.bad("当前标签已存在！");
            }

        }catch (Exception e){
            e.printStackTrace();
            log.error("新增热点标签失败：{}",e.getMessage());
            return Response.error("新增热点标签失败");
        }
    }


    @Override
    public Response deleteHotpoint(int archDeptHotId) {
        try {
            archDeptHotpointMapper.deleteHotpoint(archDeptHotId);
            return Response.success("");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除热点标签失败：{}",e.getMessage());
            return Response.error("删除热点标签失败");
        }
    }

    @Override
    public Response qryHotpoint(int pageNum,int pageSize,String archDeptCateCode) {
        try {
            Page<ArchDeptHotpoint> page = new Page<>(pageNum, pageSize);
            archDeptHotpointMapper.qryHotpoint(page,archDeptCateCode);
            return Response.success(page);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询热点标签失败：{}",e.getMessage());
            return Response.error("查询热点标签失败");
        }
    }
}
